<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _initMB(){
        mb_internal_encoding("UTF-8");
    }
protected function _initViews()
	{
	Zend_Layout::startMvc();
	$view = new Zend_View();
	$view->setEncoding("utf-8");
	$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
	$viewRenderer->setView($view);
	$view->doctype('XHTML1_STRICT');
	}
	
	public function _initAuth()
	{
    $auth = Zend_Auth::getInstance();
    $data = $auth->getStorage()->read();
    if (!isset($data->status)){
        $storage_data = new stdClass();
        $storage_data->status = 'guest';
        $auth->getStorage()->write($storage_data);
    	}
	}
	public function _initAcl(){
    Zend_Loader::loadClass('Acl');
    Zend_Loader::loadClass('CheckAccess');
    Zend_Controller_Front::getInstance()->registerPlugin(new CheckAccess());
    return new Acl();
	} 	

	protected function _initLayout()
	{
		Zend_Loader::loadClass('SetLayout');
		$front = Zend_Controller_Front::getInstance();
		$front->registerPlugin(new SetLayout());
	}
    protected function _initBars()
    {
        Zend_Loader::loadClass('Bars');
        $front = Zend_Controller_Front::getInstance();
        $front->registerPlugin(new Bars());
    }

	protected function _initDoctrine()
	{

	require_once "Doctrine/Doctrine.php";
	$this->getApplication()
		->getAutoloader()
		->pushAutoloader(array('Doctrine','autoload'),'Doctrine');

       // $ser = array(
        //    'host'=>'localhost',
         //   'port'=>11211,
         //   'persistent'=>false
        //);
       // $cache = new Doctrine_Cache_Memcache(array(
         //    'servers'=>$ser,
           //  'compression'=>false
           //  ));
       // $cache = new Doctrine_Cache_Apc();
      //  mysql://itdoc_user:zhakon1987diasik2012@localhost/itdocskz_zf
        $config = $this->getOption('doctrine');
        $manager = Doctrine_Manager::getInstance();
        $manager->openConnection($config['dsn'],'doctrine');
        $manager->setCharset("utf8");
        $manager->setCollate("utf8_general_ci");
        $manager->setAttribute('model_loading', 'conservative');
        $conn = $manager->getConnection("doctrine");
        // PDO
        $dbh = $conn->getDbh();

        $sql = "SET character_set_results = 'utf8', character_set_client = 'utf8',
        character_set_connection = 'utf8', character_set_database = 'utf8',
        character_set_server = 'utf8'";

        // аналогично
        // $sql = "SET NAMES 'utf8'";
        $dbh->query($sql);

//	$manager = Doctrine_Manager::getInstance();
      //  $conn->setAttribute(array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'" ));
        //$manager->connection(
          //  array(
            //    'mysql:dbname=itdocskz_zf;host=127.0.0.1;',
              //  'itdoc_user',
              //  'zhakon1987diasik2012',
               // array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'" ),
               // array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET 'utf8';" ),
               // array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET COLLATION SET 'utf8_general_ci';" ),
               // array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION collation_connection = 'utf8_general_ci';" )
             //  ),
           // 'doctrine' );
	//$manager->setAttribute(
	//	Doctrine::ATTR_MODEL_LOADING,
		//Doctrine::MODEL_LOADING_CONSERVATIVE,
     //   Doctrine::ATTR_QUERY_CACHE,$cache,
     //   Doctrine::ATTR_QUERY_CACHE_LIFESPAN, 3600

	//);
	//$config = $this->getOption('doctrine');
//	$conn = Doctrine_Manager::connection($config['dsn'],'doctrine');
      //  $conn->createQuery('SET NAMES utf8')->execute();
    //$conn->setAttribute(
  //      Doctrine::ATTR_RESULT_CACHE,$cache,
    //    Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 3600);


	return $conn;
	}

    protected function _initFirePhp()
    {
     //   $logger = new Zend_Log();
       // $writer = new Zend_Log_Writer_Firebug();
      //  $logger->addWriter($writer);
      //  Zend_Registry::set('logger',$logger);
    }

    protected function _initNavigation()
    {
        $this->bootstrapView();
        $view = $this->getResource('view');
		$view->doctype('XHTML1_STRICT');

        $pages = array(array (
						'module'=>'catalog',
                        'controller'=> 'menu',
                        'action'   => 'main',
						'label'			=>'Новости',
						'route'			=>'main',
                        'controller'    => 'menu',
                        'page'			=>1
						),
                        array(
						'module'		=>'catalog',
                        'controller'    => 'menu',
                        'action'        => 'catalog',
						'label'			=>'Статьи',
						'route'			=>'catalog',
						'page'			=>1
        				),
                        array(
						'module'		=>'catalog',
                        'controller'    =>'menu',
                        'action'        =>'reviews',
						'label'			=>'Обзоры',
						'route'			=>'reviews',
                        'page'			=>1
        				)

		);
        $container = new Zend_Navigation($pages);
		Zend_Registry::set('container',$container);
        $view->menu = $container;
        return $container;
    }
   // protected function _initLocale(){

       //$loc = new Zend_Locale('ru_RU');

       //$reg = Zend_Registry::getInstance();
     //  $reg->set('Zend_Locale',$loc);
   // }
	protected function _initSidebar()
	{
	   $this->bootstrap('View');
	   $view = $this->getResource('View');
	   $view->placeholder('sidebar');
	   $view->placeholder('searchform');
       //$view->placeholder('headerbox');

	   	 //$view->headScript()->prependFile('js/jquery/js/jquery-ui-1.9.2.custom.min.js');
	    //$view->headScript()->prependFile('js/jquery/js/loginscript.js');
	    //$view->headScript()->prependFile('js/jquery/js/jquery.validate.js');
	    //$view->headScript()->prependFile('js/cloud/swfobject.js');
	    //$view->headScript()->prependFile('js/cloud/cloud.js');
	   // $view->headLink()->prependStylesheet('css/jquery.pnotify/jquery.pnotify.default.css');
	   // $view->headLink()->prependStylesheet('css/jquery.pnotify/jquery.pnotify.default.icons.css');
	      
	       // ->setPostfix("</div>");
	}
}
